
project(${PROJECT_NAME} LANGUAGES CXX)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt6_add_executable(${PROJECT_NAME} MANUAL_FINALIZATION)
else()
    add_executable(${PROJECT_NAME})
endif()

## Compilation
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC ${CMAKE_SOURCE_DIR})
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC ${CMAKE_SOURCE_DIR}/utility)
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC ${CMAKE_SOURCE_DIR}/plugins)
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC ${CMAKE_SOURCE_DIR}/plugins/abstractplugin)
target_include_directories(${PROJECT_NAME} BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(${PROJECT_NAME} PRIVATE utility)

add_dependencies(${PROJECT_NAME} utility)
add_dependencies(${PROJECT_NAME} plugins)

set(APPLICATION_SOURCES_ALL)

## Sources - main
set(APPLICATION_SOURCES_MAIN
    ${CMAKE_SOURCE_DIR}/src/main.cpp
)
target_sources(${PROJECT_NAME} PRIVATE ${APPLICATION_SOURCES_MAIN})
list(APPEND APPLICATION_SOURCES_ALL ${APPLICATION_SOURCES_MAIN})
source_group("Sources" FILES ${APPLICATION_SOURCES_MAIN})

## Sources - controller
set(APPLICATION_SOURCES_CONTROLLER
${CMAKE_SOURCE_DIR}/src/controller.h
${CMAKE_SOURCE_DIR}/src/controller.cpp
)
target_sources(${PROJECT_NAME} PRIVATE ${APPLICATION_SOURCES_CONTROLLER})
list(APPEND APPLICATION_SOURCES_ALL ${APPLICATION_SOURCES_CONTROLLER})
source_group("Sources/Controller" FILES ${APPLICATION_SOURCES_CONTROLLER})

## Sources - pluginsmanager
set(APPLICATION_SOURCES_PLUGINS_MANAGER
${CMAKE_SOURCE_DIR}/src/pluginsmanager.h
${CMAKE_SOURCE_DIR}/src/pluginsmanager.cpp
)
target_sources(${PROJECT_NAME} PRIVATE ${APPLICATION_SOURCES_PLUGINS_MANAGER})
list(APPEND APPLICATION_SOURCES_ALL ${APPLICATION_SOURCES_PLUGINS_MANAGER})
source_group("Sources/PluginsManager" FILES ${APPLICATION_SOURCES_PLUGINS_MANAGER})

## Sources - ui
set(APPLICATION_SOURCES_UI
    ${CMAKE_SOURCE_DIR}/src/ui/mainwindow.ui
    ${CMAKE_SOURCE_DIR}/src/ui/mainwindow.h
    ${CMAKE_SOURCE_DIR}/src/ui/mainwindow.cpp
)
target_sources(${PROJECT_NAME} PRIVATE ${APPLICATION_SOURCES_UI})
list(APPEND APPLICATION_SOURCES_ALL ${APPLICATION_SOURCES_UI})
source_group("Sources/UI" FILES ${APPLICATION_SOURCES_UI})

# ## Resources
include(${CMAKE_SOURCE_DIR}/cmake/assets.cmake)

## Translations
file(GLOB_RECURSE TS_UTILITY_SOURCES
    ${CMAKE_SOURCE_DIR}/utility/*.ui
    ${CMAKE_SOURCE_DIR}/utility/*.h
    ${CMAKE_SOURCE_DIR}/utility/*.c
    ${CMAKE_SOURCE_DIR}/utility/*.cpp
    ${CMAKE_SOURCE_DIR}/utility/*.cxx
    ${CMAKE_SOURCE_DIR}/utility/*.c++
)
file(GLOB_RECURSE TS_ABSTRACTPLUGIN_SOURCES
    ${CMAKE_SOURCE_DIR}/plugins/abstractplugin/*.ui
    ${CMAKE_SOURCE_DIR}/plugins/abstractplugin/*.h
    ${CMAKE_SOURCE_DIR}/plugins/abstractplugin/*.c
    ${CMAKE_SOURCE_DIR}/plugins/abstractplugin/*.cpp
    ${CMAKE_SOURCE_DIR}/plugins/abstractplugin/*.cxx
    ${CMAKE_SOURCE_DIR}/plugins/abstractplugin/*.c++
)
set(TS_SOURCE_FILES ${APPLICATION_SOURCES_ALL} ${TS_UTILITY_SOURCES} ${TS_ABSTRACTPLUGIN_SOURCES})

include(${CMAKE_SOURCE_DIR}/cmake/translations.cmake)

## Deployment
include(${CMAKE_SOURCE_DIR}/cmake/deployment.cmake)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(${PROJECT_NAME})
endif()
